package shizhan;

import java.lang.reflect.*;

public class shizhan1Test {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        System.out.println("====获取类的信息=======");
        Class clz1=Class.forName("shizhan.shizhan1");
        Class clz=shizhan1.class;
        String fullName=clz.getName();
        System.out.println("以下是"+fullName+"类的类型信息");
        System.out.println("====获取类名=========");
        System.out.println("以下是"+clz1.getSimpleName()+"的类名");
        System.out.println("====获得类的修饰符======");
        int modifier = clz.getModifiers();
        System.out.println(clz1.getSimpleName()+"：的修饰符");
        if ((modifier & Modifier.PUBLIC)==Modifier.PUBLIC){
            System.out.println("访问修饰符是：public");
        }
        System.out.println("=====获取"+clz1.getSimpleName()+"的父类类名======");
        Class superClass =clz.getSuperclass();
        System.out.println(clz1+"的父类是："+superClass.getName());
        System.out.println("=====获取构造方法名=======");
        Constructor<?>[] declaredConstructors = shizhan1.class.getDeclaredConstructors();
        for (Constructor con:declaredConstructors){
            System.out.println("构造方法名是："+con.getName());
        }
        System.out.println("=====获取属性=======");
        Field[] declaredFields = shizhan1.class.getDeclaredFields();
        for (Field field:declaredFields){
            System.out.println("属性名是："+field.getName());
            System.out.println("类型是："+field.getType());
        }
        System.out.println("=====获取方法信息=======");
        Method[] declaredMethods = shizhan1.class.getDeclaredMethods();
        for (Method method:declaredMethods){
            System.out.println("方法名是："+method.getName());
            System.out.println("返回值类型是："+method.getReturnType().getName());
        }
        System.out.println("=====进行赋值与取值======");
        Method sayHello = clz.getDeclaredMethod("sayHello");
        Constructor<shizhan1> declaredConstructors1 = shizhan1.class.getDeclaredConstructor(String.class);
        declaredConstructors1.setAccessible(true);
        shizhan1 shizhan1=declaredConstructors1.newInstance("政黄");
        sayHello.invoke(shizhan1);
        System.out.println("====方法调用====");
        Method cry = clz.getDeclaredMethod("cry");
        Constructor<shizhan1> declaredConstructors11 = shizhan1.class.getDeclaredConstructor(String.class);
        declaredConstructors11.setAccessible(true);
        shizhan1 shizhan11=declaredConstructors1.newInstance("政黄111");
        cry.invoke(shizhan11);
    }
}
